Imports System.Data.SqlClient

Public Class cls_documentodetalle_

    Implements ICloneable

#Region "Variables ..."
    Private int_iddocumentodetalle As Integer = 0
    Private int_idarticulo As Integer = 0
    Private str_codigo As String = ""
    Private str_nombre As String = ""
    Private str_descripcion As String = ""
    Private dbl_valor As Double = 0
    Private dbl_cantidad As Double = 0
    Private dbl_subcantidad As Double = 0
    Private int_idmoneda As Integer = 0
    Private dbl_cotizacionvalor As Double = 0
    Private int_iddocumento As Integer = 0
    Private int_idunidaddetalle As Integer = 0
    Private dec_descuento As Decimal = 0
    Private dec_descuentoP As Decimal = 0
    Private dec_recargo As Decimal = 0
    Private dec_recargoP As Decimal = 0
    Private dec_alteracion As Decimal = 0
    Private dec_alteracionP As Decimal = 0
    Private dec_valorfinal As Decimal = 0


    Private obj_documento As cls_documento_
    Private obj_articulo As cls_articulo_
    Private obj_unidaddetalle As cls_unidaddetalle_

    Private col_Items As Collections.Generic.List(Of cls_documentodetalle_) = Nothing
#End Region

#Region "Propiedades ..."
    ReadOnly Property This
        Get
            Return Me
        End Get
    End Property
    ReadOnly Property ThisDescripcion As String
        Get
            Return Me.ToString
        End Get
    End Property
    ReadOnly Property pKey
        Get
            Return iddocumentodetalle
        End Get
    End Property
    Property iddocumentodetalle() As Integer
        Get
            iddocumentodetalle = int_iddocumentodetalle
        End Get
        Set(ByVal value As Integer)
            int_iddocumentodetalle = value
        End Set
    End Property
    Property idarticulo() As Integer
        Get
            idarticulo = int_idarticulo
        End Get
        Set(ByVal value As Integer)
            int_idarticulo = value
        End Set
    End Property
    Property codigo() As String
        Get
            codigo = str_codigo
        End Get
        Set(ByVal value As String)
            str_codigo = value
        End Set
    End Property
    Property nombre() As String
        Get
            nombre = str_nombre
        End Get
        Set(ByVal value As String)
            str_nombre = value
        End Set
    End Property
    Property descripcion() As String
        Get
            descripcion = str_descripcion
        End Get
        Set(ByVal value As String)
            str_descripcion = value
        End Set
    End Property
    Property valor() As Decimal
        Get
            valor = dbl_valor
        End Get
        Set(ByVal value As Decimal)
            dbl_valor = value
        End Set
    End Property
    Property cantidad() As Double
        Get
            cantidad = dbl_cantidad
        End Get
        Set(ByVal value As Double)
            dbl_cantidad = value
        End Set
    End Property
    Property subcantidad() As Double
        Get
            subcantidad = dbl_subcantidad
        End Get
        Set(ByVal value As Double)
            dbl_subcantidad = value
        End Set
    End Property
    Property idmoneda() As Integer
        Get
            idmoneda = int_idmoneda
        End Get
        Set(ByVal value As Integer)
            int_idmoneda = value
        End Set
    End Property
    Property cotizacionvalor() As Double
        Get
            cotizacionvalor = dbl_cotizacionvalor
        End Get
        Set(ByVal value As Double)
            dbl_cotizacionvalor = value
        End Set
    End Property
    Property iddocumento() As Integer
        Get
            iddocumento = int_iddocumento
        End Get
        Set(ByVal value As Integer)
            int_iddocumento = value
        End Set
    End Property
    Property idunidaddetalle As Integer
        Get
            idunidaddetalle = int_idunidaddetalle
        End Get
        Set(ByVal value As Integer)
            int_idunidaddetalle = value
        End Set
    End Property
    Property descuento As Decimal
        Get
            descuento = dec_descuento
        End Get
        Set(ByVal value As Decimal)
            dec_descuento = value
        End Set
    End Property
    Property descuentoP As Decimal
        Get
            descuentoP = dec_descuentoP
        End Get
        Set(ByVal value As Decimal)
            dec_descuentoP = value
        End Set
    End Property
    Property recargo As Decimal
        Get
            recargo = dec_recargo
        End Get
        Set(ByVal value As Decimal)
            dec_recargo = value
        End Set
    End Property
    Property recargoP As Decimal
        Get
            recargoP = dec_recargoP
        End Get
        Set(ByVal value As Decimal)
            dec_recargoP = value
        End Set
    End Property
    Property alteracion As Decimal
        Get
            alteracion = dec_alteracion
        End Get
        Set(ByVal value As Decimal)
            dec_alteracion = value
        End Set
    End Property
    Property alteracionP As Decimal
        Get
            alteracionP = dec_alteracionP
        End Get
        Set(ByVal value As Decimal)
            dec_alteracionP = value
        End Set
    End Property
    Property valorfinal As Decimal
        Get
            valorfinal = dec_valorfinal
        End Get
        Set(ByVal value As Decimal)
            dec_valorfinal = value
        End Set
    End Property
    Property documento() As cls_documento_
        Get
            If IsNothing(obj_documento) Then
                obj_documento = New cls_documento_
                If Not obj_documento.Buscar(iddocumento) Then
                    obj_documento = Nothing
                End If
            End If
            documento = obj_documento
        End Get
        Set(ByVal value As cls_documento_)
            obj_documento = value
        End Set
    End Property
    Property unidaddetalle() As cls_unidaddetalle_
        Get
            If IsNothing(obj_unidaddetalle) Then
                obj_unidaddetalle = New cls_unidaddetalle_
                If Not obj_unidaddetalle.Buscar(idunidaddetalle) Then
                    obj_unidaddetalle = Nothing
                End If
            End If
            unidaddetalle = obj_unidaddetalle
        End Get
        Set(ByVal value As cls_unidaddetalle_)
            obj_unidaddetalle = value
        End Set
    End Property
    Property articulo() As cls_articulo_
        Get
            If IsNothing(obj_articulo) Then
                obj_articulo = New cls_articulo_
                If Not obj_articulo.Buscar(idarticulo) Then
                    obj_articulo = Nothing
                End If
            End If
            articulo = obj_articulo
        End Get
        Set(ByVal value As cls_articulo_)
            obj_articulo = value
        End Set
    End Property
    Property Items() As Collections.Generic.List(Of cls_documentodetalle_)
        Get
            Items = col_Items
        End Get
        Set(ByVal value As Collections.Generic.List(Of cls_documentodetalle_))
            col_Items = value
        End Set
    End Property
#End Region

    Private Sub CargarColeccion(ByVal obj_Reader As SqlDataReader)
        col_Items = New Collections.Generic.List(Of cls_documentodetalle_)
        While obj_Reader.Read()
            Dim Elemento As New cls_documentodetalle_
            Elemento.int_iddocumentodetalle = (obj_Reader.GetValue(obj_Reader.GetOrdinal("iddocumentodetalle")))

            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idarticulo"))) = False Then
                Elemento.int_idarticulo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idarticulo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("codigo"))) = False Then
                Elemento.str_codigo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("codigo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("nombre"))) = False Then
                Elemento.str_nombre = (obj_Reader.GetValue(obj_Reader.GetOrdinal("nombre")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descripcion"))) = False Then
                Elemento.str_descripcion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descripcion")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("valor"))) = False Then
                Elemento.dbl_valor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("valor")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("cantidad"))) = False Then
                Elemento.dbl_cantidad = (obj_Reader.GetValue(obj_Reader.GetOrdinal("cantidad")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("subcantidad"))) = False Then
                Elemento.dbl_subcantidad = (obj_Reader.GetValue(obj_Reader.GetOrdinal("subcantidad")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idmoneda"))) = False Then
                Elemento.int_idmoneda = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmoneda")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("cotizacionvalor"))) = False Then
                Elemento.dbl_cotizacionvalor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("cotizacionvalor")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("iddocumento"))) = False Then
                Elemento.int_iddocumento = (obj_Reader.GetValue(obj_Reader.GetOrdinal("iddocumento")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idunidaddetalle"))) = False Then
                Elemento.int_idunidaddetalle = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idunidaddetalle")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descuento"))) = False Then
                Elemento.dec_descuento = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descuento")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoP"))) = False Then
                Elemento.dec_descuentoP = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoP")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("recargo"))) = False Then
                Elemento.dec_recargo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("recargo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoP"))) = False Then
                Elemento.dec_recargoP = (obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoP")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("alteracion"))) = False Then
                Elemento.dec_alteracion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("alteracion")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("alteracionP"))) = False Then
                Elemento.dec_alteracionP = (obj_Reader.GetValue(obj_Reader.GetOrdinal("alteracionP")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("valorfinal"))) = False Then
                Elemento.dec_valorfinal = (obj_Reader.GetValue(obj_Reader.GetOrdinal("valorfinal")))
            End If
            col_Items.Add(Elemento)
        End While
    End Sub

    Private Sub CargarVariables(ByVal obj_Reader As SqlDataReader)
        obj_Reader.Read()
        int_iddocumentodetalle = (obj_Reader.GetValue(obj_Reader.GetOrdinal("iddocumentodetalle")))

        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idarticulo"))) = False Then
            int_idarticulo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idarticulo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("codigo"))) = False Then
            str_codigo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("codigo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("nombre"))) = False Then
            str_nombre = (obj_Reader.GetValue(obj_Reader.GetOrdinal("nombre")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descripcion"))) = False Then
            str_descripcion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descripcion")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("valor"))) = False Then
            dbl_valor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("valor")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("cantidad"))) = False Then
            dbl_cantidad = (obj_Reader.GetValue(obj_Reader.GetOrdinal("cantidad")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("subcantidad"))) = False Then
            dbl_subcantidad = (obj_Reader.GetValue(obj_Reader.GetOrdinal("subcantidad")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idmoneda"))) = False Then
            int_idmoneda = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmoneda")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("cotizacionvalor"))) = False Then
            dbl_cotizacionvalor = (obj_Reader.GetValue(obj_Reader.GetOrdinal("cotizacionvalor")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("iddocumento"))) = False Then
            int_iddocumento = (obj_Reader.GetValue(obj_Reader.GetOrdinal("iddocumento")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idunidaddetalle"))) = False Then
            int_idunidaddetalle = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idunidaddetalle")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descuento"))) = False Then
            dec_descuento = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descuento")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoP"))) = False Then
            dec_descuentoP = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descuentoP")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("recargo"))) = False Then
            dec_recargo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("recargo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoP"))) = False Then
            dec_recargoP = (obj_Reader.GetValue(obj_Reader.GetOrdinal("recargoP")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("alteracion"))) = False Then
            dec_alteracion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("alteracion")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("alteracionP"))) = False Then
            dec_alteracionP = (obj_Reader.GetValue(obj_Reader.GetOrdinal("alteracionP")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("valorfinal"))) = False Then
            dec_valorfinal = (obj_Reader.GetValue(obj_Reader.GetOrdinal("valorfinal")))
        End If
    End Sub

    Public Function Nuevo(Optional ByVal ObtenerID As Boolean = False) As Boolean
        Nuevo = False
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "documentodetalle__Nuevo"
                .Parameters.Add("@idarticulo", SqlDbType.Int).Value = IIf(int_idarticulo = 0, DBNull.Value, int_idarticulo)
                .Parameters.Add("@codigo", SqlDbType.NVarChar).Value = str_codigo
                .Parameters.Add("@nombre", SqlDbType.NVarChar).Value = str_nombre
                .Parameters.Add("@descripcion", SqlDbType.NVarChar).Value = str_descripcion
                .Parameters.Add("@valor", SqlDbType.Decimal).Value = dbl_valor
                .Parameters.Add("@cantidad", SqlDbType.Decimal).Value = dbl_cantidad
                .Parameters.Add("@subcantidad", SqlDbType.Decimal).Value = dbl_subcantidad
                .Parameters.Add("@idmoneda", SqlDbType.Int).Value = int_idmoneda
                .Parameters.Add("@cotizacionvalor", SqlDbType.Decimal).Value = dbl_cotizacionvalor
                .Parameters.Add("@iddocumento", SqlDbType.Int).Value = int_iddocumento
                .Parameters.Add("@idunidaddetalle", SqlDbType.Int).Value = int_idunidaddetalle
                .Parameters.Add("@descuento", SqlDbType.Decimal).Value = dec_descuento
                .Parameters.Add("@descuentoP", SqlDbType.Decimal).Value = dec_descuentoP
                .Parameters.Add("@recargo", SqlDbType.Decimal).Value = dec_recargo
                .Parameters.Add("@recargoP", SqlDbType.Decimal).Value = dec_recargoP
                .Parameters.Add("@alteracion", SqlDbType.Decimal).Value = dec_alteracion
                .Parameters.Add("@alteracionP", SqlDbType.Decimal).Value = dec_alteracionP
                .Parameters.Add("@valorfinal", SqlDbType.Decimal).Value = dec_valorfinal
                .ExecuteNonQuery()
            End With
            Nuevo = True
            If ObtenerID Then
                CargarUltimo()
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Crear el registro de documentodetalle_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Function

    Public Sub Modificar()
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "documentodetalle__Modificar"
                .Parameters.Add("@iddocumentodetalle", SqlDbType.Int).Value = int_iddocumentodetalle
                .Parameters.Add("@idarticulo", SqlDbType.Int).Value = IIf(int_idarticulo = 0, DBNull.Value, int_idarticulo)
                .Parameters.Add("@codigo", SqlDbType.NVarChar).Value = str_codigo
                .Parameters.Add("@nombre", SqlDbType.NVarChar).Value = str_nombre
                .Parameters.Add("@descripcion", SqlDbType.NVarChar).Value = str_descripcion
                .Parameters.Add("@valor", SqlDbType.Decimal).Value = dbl_valor
                .Parameters.Add("@cantidad", SqlDbType.Decimal).Value = dbl_cantidad
                .Parameters.Add("@subcantidad", SqlDbType.Decimal).Value = dbl_subcantidad
                .Parameters.Add("@idmoneda", SqlDbType.Int).Value = int_idmoneda
                .Parameters.Add("@cotizacionvalor", SqlDbType.Decimal).Value = dbl_cotizacionvalor
                .Parameters.Add("@iddocumento", SqlDbType.Int).Value = int_iddocumento
                .Parameters.Add("@idunidaddetalle", SqlDbType.Int).Value = int_idunidaddetalle
                .Parameters.Add("@descuento", SqlDbType.Decimal).Value = dec_descuento
                .Parameters.Add("@descuentoP", SqlDbType.Decimal).Value = dec_descuentoP
                .Parameters.Add("@recargo", SqlDbType.Decimal).Value = dec_recargo
                .Parameters.Add("@recargoP", SqlDbType.Decimal).Value = dec_recargoP
                .Parameters.Add("@alteracion", SqlDbType.Decimal).Value = dec_alteracion
                .Parameters.Add("@alteracionP", SqlDbType.Decimal).Value = dec_alteracionP
                .Parameters.Add("@valorfinal", SqlDbType.Decimal).Value = dec_valorfinal
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Modificar el registro de documentodetalle_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Sub Eliminar(ByVal iddocumentodetalle As Integer)
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "documentodetalle__Eliminar"
                .Parameters.Add("@iddocumentodetalle", SqlDbType.Int).Value = iddocumentodetalle
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Eliminar el registro de documentodetalle_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Function Buscar(ByVal iddocumentodetalle As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            Buscar = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "documentodetalle__Buscar"
                .Parameters.Add("@iddocumentodetalle", SqlDbType.Int).Value = iddocumentodetalle
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                Buscar = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Buscar el registro de documentodetalle_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Sub CargarUltimo()
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "documentodetalle__CargarUltimo"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarUltimo registro de documentodetalle_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Sub

    Public Function CargarTodos() As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarTodos = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "documentodetalle__CargarTodos"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarTodos = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarTodos los registros de documentodetalle_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj_documentodetalle_Clon As New cls_documentodetalle_
        obj_documentodetalle_Clon.int_iddocumentodetalle = Me.int_iddocumentodetalle
        obj_documentodetalle_Clon.int_idarticulo = Me.int_idarticulo
        obj_documentodetalle_Clon.str_codigo = Me.str_codigo
        obj_documentodetalle_Clon.str_nombre = Me.str_nombre
        obj_documentodetalle_Clon.str_descripcion = Me.str_descripcion
        obj_documentodetalle_Clon.dbl_valor = Me.dbl_valor
        obj_documentodetalle_Clon.dbl_cantidad = Me.dbl_cantidad
        obj_documentodetalle_Clon.dbl_subcantidad = Me.dbl_subcantidad
        obj_documentodetalle_Clon.int_idmoneda = Me.int_idmoneda
        obj_documentodetalle_Clon.dbl_cotizacionvalor = Me.dbl_cotizacionvalor
        obj_documentodetalle_Clon.int_iddocumento = Me.int_iddocumento
        obj_documentodetalle_Clon.int_idunidaddetalle = Me.int_idunidaddetalle
        obj_documentodetalle_Clon.dec_descuento = Me.dec_descuento
        obj_documentodetalle_Clon.dec_descuentoP = Me.dec_descuentoP
        obj_documentodetalle_Clon.dec_recargo = Me.dec_recargo
        obj_documentodetalle_Clon.dec_recargoP = Me.dec_recargoP
        obj_documentodetalle_Clon.dec_alteracion = Me.dec_alteracion
        obj_documentodetalle_Clon.dec_alteracionP = Me.dec_alteracionP
        obj_documentodetalle_Clon.dec_valorfinal = Me.dec_valorfinal
        
        obj_documentodetalle_Clon.col_Items = Me.col_Items
        Return obj_documentodetalle_Clon
    End Function

    Function CargarXiddocumento(ByVal int_iddocumento As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarXiddocumento = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "documentodetalle__CargarXiddocumento"
                .Parameters.Add("@iddocumento", SqlDbType.Int).Value = int_iddocumento
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarXiddocumento = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarTodos los registros de documentodetalle_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Sub Recalcular()
        descuento = (descuentoP * (cantidad * valor)) / 100
        recargo = (recargoP * (cantidad * valor)) / 100
        alteracion = (alteracionP * (cantidad * valor)) / 100
        valorfinal = (cantidad * valor) + recargo - descuento '+ alteracion
    End Sub

End Class
